<div class="form">
    <?php echo validation_errors(); ?>
    
    <?php echo form_open($action); ?>

        <div id="tabs">
            <ul>
                <li><a href="#tabs-1">帐号信息</a></li>
                <li><a href="#tabs-2">员工信息</a></li>
                <li><a href="#tabs-3">员工组权限</a></li>
            </ul>
            <div id="tabs-1">
                <div>
                    <label class="span-3">用户名</label>
                    <input class="text span-4" name="u_name" readonly="readonly"
                           value="<?php echo set_value('u_name', $user['u_name']); ?>" />
                    <?php if (strpos($action, 'update')): ?>
                    <div class="span-2 info">不能修改</div>
                    <?php endif; ?>
                    <div class="clear"></div>
                </div>
                <?php if (strpos($action, 'update')): ?>
                <div>
                    <label class="span-3">重新设置口令</label>
                    <label class="span-1">
                        <?php echo form_checkbox("reset_password", "1", set_value('reset_password') == '1', 'id="reset_password"'); ?>
                    </label>
                    <div class="clear"></div>
                </div>
                <?php endif; ?>
                <div id="password-div">
                    <label class="span-3">口令<span class="required">*</span></label>
                    <input class="text span-4" type="password" name="u_password" />
                    <label class="span-3">再输一次<span class="required">*</span></label>
                    <input class="text span-4" type="password" name="u_password_again" />
                    <div class="span-10 info">请输入至少6位，建议由数字，大小写字母和特殊字符组成</div>
                    <div class="clear"></div>
                </div>
                <div>
                    <label class="span-3">有效期自</label>
                    <input class="text span-4 normal-date" name="u_first_date" readonly="readonly"
                           value="<?php echo set_value('u_first_date', $user['u_first_date']); ?>" />
                    <label class="span-3">至</label>
                    <input class="text span-4 normal-date" name="u_last_date" readonly="readonly"
                           value="<?php echo set_value('u_last_date', $user['u_last_date']); ?>" />
                    <div class="clear"></div>
                </div>
            </div>
            <div id="tabs-2">
                <div>
                    <label class="span-3">姓名<span class="required">*</span></label>
                    <input class="text span-4" name="u_real_name" 
                           value="<?php echo set_value('u_real_name', $user['u_real_name']); ?>" />
                    <div class="clear"></div>
                </div>
                <div>
                    <label class="span-3">性别</label>
                    <?php 
                        $sexs = array('' => '', '男' => '男', '女' => '女');
                        echo form_dropdown('u_sex', $sexs, set_value('u_sex', $user['u_sex']), 'class="span-4"');
                    ?>
                    <div class="clear"></div>
                </div>
                <div>
                    <label class="span-3">联系电话</label>
                    <input class="text span-4" name="u_telephone" 
                           value="<?php echo set_value('u_telephone', $user['u_telephone']); ?>" />
                    <div class="clear"></div>
                </div>
            </div>
            <div id="tabs-3">
                <?php foreach ($roles as $r_id => $r_name): ?>
                <div>
                    <span class="span-1">&nbsp;</span>
                    <label class="span-5 left">
                        <?php echo form_checkbox("ur_rid[]", $r_id, isset($user_roles[$r_id])); ?>
                        <?php echo $r_name; ?>
                    </label>
                    <label class="span-3">有效期自</label>
                    <?php echo form_input("ur_first_date[$r_id]", isset($user_roles[$r_id]) ? $user_roles[$r_id]['ur_first_date'] : "", 'class="text span-4 normal-date" readonly="readonly"'); ?>
                    <label class="span-1">至</label>
                    <?php echo form_input("ur_last_date[$r_id]", isset($user_roles[$r_id]) ? $user_roles[$r_id]['ur_last_date'] : "", 'class="text span-4 normal-date" readonly="readonly"'); ?>
                    <div class="clear"></div>
                </div>
                <?php endforeach; ?>
            </div>
        </div>
        <div class="form-actions">
            <input type="submit" class="form-submit" value="保存" />
        </div>
    </form>
</div>
<script>
    $(function() {
        $("#tabs").tabs();

        $(".normal-date").datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: "yy-mm-dd",
        });
        
        /**
         * 角色复选框 点击事件
         */
        $("#tabs-3 input[type=checkbox]").click(function(){
            var divObj = $(this).parent().parent();
            if (this.checked) {
                divObj.children("input[name^=ur_first_date]").val('<?php echo date('Y-m-d'); ?>');
                divObj.children("input[name^=ur_last_date]").val('<?php echo (date('Y') + 10) . '-12-31'; ?>');
            } else {
                divObj.children("input[name^=ur_first_date]").val('');
                divObj.children("input[name^=ur_last_date]").val('');
            }
        });
        
        <?php if (strpos($action, 'update')): ?>
        
        /**
         * 重新设置密码 点击事件
         */
        $("#reset_password").click(function(){
            if (this.checked) {
                $("#password-div").show();
            } else {
                $("#password-div").hide();
            }
        });
        
        /**
         * 设置属性，触发点击事件
         */
        if ($("#reset_password").prop("checked")) {
            $("#password-div").show();
        } else {
            $("#password-div").hide();
        }
        <?php endif; ?>
    });
</script>